home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / util.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  64KB  |  2,014 lines

  1. /***********************************************************************/
  2. /* UTIL.C - Utility routines                                           */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1995 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 5314
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38.  
  39. /*
  40. $Id: util.c 2.0 1995/01/26 16:32:18 MH Release MH $
  41. */
  42.  
  43. #include <stdio.h>
  44. #include "the.h"
  45. #include "proto.h"
  46.  
  47. /*--------------------------- common data -----------------------------*/
  48.  static CHARTYPE *recv[MAX_RECV];
  49.  static LENGTHTYPE recv_len[MAX_RECV];
  50.  static short add_recv=(-1);
  51.  static short retr_recv=(-1);
  52.  static short num_recv=0;
  53.  
  54. /*man***************************************************************************
  55. NAME
  56.      memreveq - search buffer reversed for character
  57.  
  58. SYNOPSIS
  59.      short memreveq(buffer,chr,max_length)
  60.      CHARTYPE *buffer;
  61.      CHARTYPE ch;
  62.      short max_length;
  63.  
  64. DESCRIPTION
  65.      The memreveq function searches the buffer from the right for the
  66.      first character equal to the supplied character.
  67.  
  68. RETURN VALUE
  69.      If successful, returns the position of first matching character
  70.      or (-1) if unsuccessful.
  71.  
  72. SEE ALSO
  73.      strzreveq, memrevne
  74. *******************************************************************************/
  75. #ifdef PROTO
  76. short memreveq(CHARTYPE *buffer,CHARTYPE ch,short max_len)
  77. #else
  78. short memreveq(buffer,ch,max_len)
  79. CHARTYPE *buffer,ch;
  80. short max_len;
  81. #endif
  82. /***********************************************************************/
  83. {
  84. /*--------------------------- local data ------------------------------*/
  85.  register short len=max_len;
  86. /*--------------------------- processing ------------------------------*/
  87.  for (--len; len>=0 && buffer[len]!=ch; len--);
  88.  return(len);
  89. }
  90. /*man***************************************************************************
  91. NAME
  92.      memrevne - search buffer reversed for NOT character
  93.  
  94. SYNOPSIS
  95.      #include "the.h"
  96.  
  97.      short memrevne(buffer,known_char,max_len)
  98.      CHARTYPE *buffer;
  99.      CHARTYPE known_char;
  100.      short max_len;
  101.  
  102. DESCRIPTION
  103.      The memrevne function searches the buffer from the right for first
  104.      character NOT equal to the supplied character.
  105.  
  106. RETURN VALUE
  107.      If successful, returns the position of first NON-matching character
  108.      or (-1) if unsuccessful.
  109.  
  110. SEE ALSO
  111.      strzrevne, strzne
  112. *******************************************************************************/
  113. #ifdef PROTO
  114. short memrevne(CHARTYPE *buffer,CHARTYPE known_char,short max_len)
  115. #else
  116. short memrevne(buffer,known_char,max_len)
  117. CHARTYPE *buffer;
  118. CHARTYPE known_char;
  119. short max_len;
  120. #endif
  121. {
  122. /*--------------------------- local data ------------------------------*/
  123.  register short len=max_len;
  124. /*--------------------------- processing ------------------------------*/
  125.  for (--len; len>=0 && buffer[len]==known_char; len--);
  126.  return(len);
  127. }
  128. /*man***************************************************************************
  129. NAME
  130.      meminschr - insert character into buffer
  131.  
  132. SYNOPSIS
  133.      #include "the.h"
  134.  
  135.      CHARTYPE *meminschr(buffer,chr,location,max_length,curr_length)
  136.      CHARTYPE *buffer;
  137.      CHARTYPE chr;
  138.      short location,max_length,curr_length;
  139.  
  140. DESCRIPTION
  141.      The meminschr inserts the supplied 'chr' into the buffer 'buffer'
  142.      before the 'location' specified. 'location' is an offset (0 based)
  143.      from the start of 'buffer'.
  144.      The 'buffer' will not be allowed to have more than 'max_length'
  145.      characters, so if the insertion of the character causes the
  146.      'max_length' to be exceeded, the last character of 'buffer' will
  147.      be lost.
  148.  
  149. RETURN VALUE
  150.      A pointer to the same 'buffer' as was supplied.
  151.  
  152. SEE ALSO
  153.     meminsstr, memdelchr
  154.  
  155. *******************************************************************************/
  156. #ifdef PROTO
  157. CHARTYPE *meminschr(CHARTYPE *buffer,CHARTYPE chr,short location,
  158.                 short max_length,short curr_length)
  159. #else
  160. CHARTYPE *meminschr(buffer,chr,location,max_length,curr_length)
  161. CHARTYPE *buffer;
  162. CHARTYPE chr;
  163. short location,max_length,curr_length;
  164. #endif
  165. {
  166. /*--------------------------- local data ------------------------------*/
  167.  register short i=0;
  168. /*--------------------------- processing ------------------------------*/
  169.  for (i=curr_length;i > location;i--)
  170.      if (i < max_length)
  171.        buffer[i] = buffer[i-1];
  172.  if (location < max_length)
  173.     buffer[location] = chr;
  174.  return(buffer);
  175. }
  176. /*man***************************************************************************
  177. NAME
  178.      meminsmem - insert memory into buffer
  179.  
  180. SYNOPSIS
  181.      #include "the.h"
  182.  
  183.      CHARTYPE *meminsmem(buffer,str,len,location,max_length,curr_length)
  184.      CHARTYPE *buffer;
  185.      CHARTYPE *str;
  186.      short len,location,max_length,curr_length;
  187.  
  188. DESCRIPTION
  189.      The meminsmem function inserts the supplied 'str' into the buffer 'buffer'
  190.      before the 'location' specified. 'location' is an offset (0 based)
  191.      from the start of 'buffer'.
  192.      The 'buffer' will not be allowed to have more than 'max_length'
  193.      characters, so if the insertion of the string causes the
  194.      'max_length' to be exceeded, the last character(s) of 'buffer' will
  195.      be lost.
  196.  
  197. RETURN VALUE
  198.      A pointer to the same 'buffer' as was supplied.
  199.  
  200. SEE ALSO
  201.     meminschr
  202.  
  203. *******************************************************************************/
  204. #ifdef PROTO
  205. CHARTYPE *meminsmem(CHARTYPE *buffer,CHARTYPE *str,short len,short location,
  206.                 short max_length,short curr_length)
  207. #else
  208. CHARTYPE *meminsmem(buffer,str,len,location,max_length,curr_length)
  209. CHARTYPE *buffer,*str;
  210. short len,location,max_length,curr_length;
  211. #endif
  212. {
  213. /*--------------------------- local data ------------------------------*/
  214.  register short i=0;
  215. /*--------------------------- processing ------------------------------*/
  216.  for (i=curr_length;i > location;i--)
  217.      if (i+len-1 < max_length)
  218.        buffer[i+len-1] = buffer[i-1];
  219.  for (i=0;i<len;i++)
  220.      if (location+i < max_length)
  221.        buffer[location+i] = str[i];
  222.  return(buffer);
  223. }
  224. /*man***************************************************************************
  225. NAME
  226.      memdelchr - delete character(s) from buffer
  227.  
  228. SYNOPSIS
  229.      #include "the.h"
  230.  
  231.      CHARTYPE *memdelchr(buffer,location,curr_length,num_chars)
  232.      CHARTYPE *buffer;
  233.      short location,curr_length,num_chars;
  234.  
  235. DESCRIPTION
  236.      The memdelchr deletes the supplied number of characters from the
  237.      buffer starting at the 'location' specified. 'location' is an offset (0 based)
  238.      from the start of 'buffer'.
  239.      For each character deleted, what was the last character in buffer;
  240.      based on 'curr_length' will be replaced with a space.
  241.  
  242. RETURN VALUE
  243.      A pointer to the same 'buffer' as was supplied.
  244.  
  245. SEE ALSO
  246.     meminschr
  247.  
  248. *******************************************************************************/
  249. #ifdef PROTO
  250. CHARTYPE *memdelchr(CHARTYPE *buffer,short location,short curr_length,short num_chars)
  251. #else
  252. CHARTYPE *memdelchr(buffer,location,curr_length,num_chars)
  253. CHARTYPE *buffer;
  254. short location,curr_length,num_chars;
  255. #endif
  256. {
  257. /*--------------------------- local data ------------------------------*/
  258.  register short i=0;
  259. /*--------------------------- processing ------------------------------*/
  260.  for (i=location;i <curr_length;i++)
  261.      if (i+num_chars >= curr_length)
  262.         buffer[i] = ' ';
  263.       else
  264.         buffer[i] = buffer[i+num_chars];
  265.  return(buffer);
  266. }
  267. /*man***************************************************************************
  268. NAME
  269.      strzne - search string for NOT character
  270.  
  271. SYNOPSIS
  272.      #include "the.h"
  273.  
  274.      short strzne(str,chr)
  275.      CHARTYPE *str;
  276.      CHARTYPE ch;
  277.  
  278. DESCRIPTION
  279.      The strzne function searches the string from the left for the first
  280.      character NOT equal to the supplied character.
  281.  
  282. RETURN VALUE
  283.      If successful, returns the position of first NON-matching character
  284.      or (-1) if unsuccessful.
  285.  
  286. SEE ALSO
  287.      strzrevne, memrevne
  288. *******************************************************************************/
  289. #ifdef PROTO
  290. short strzne(CHARTYPE *str,CHARTYPE ch)
  291. #else
  292. short strzne(str,ch)
  293. CHARTYPE *str;
  294. CHARTYPE ch;
  295. #endif
  296. {
  297. /*--------------------------- local data ------------------------------*/
  298.  register short len=0;
  299.  register short  i = 0;
  300. /*--------------------------- processing ------------------------------*/
  301.  len = strlen(str);
  302.  for (; i<len && str[i]==ch; i++);
  303.  if (i>=len)
  304.     i = (-1);
  305.  return(i);
  306. }
  307. /*man***************************************************************************
  308. NAME
  309.      my_strdup - equivalent to strdup
  310.  
  311. SYNOPSIS
  312.      CHARTYPE *my_strdup(str)
  313.      CHARTYPE *str;
  314.  
  315. DESCRIPTION
  316.      The my_strdup function duplicates the supplied string.
  317.  
  318. RETURN VALUE
  319.      If successful, returns a pointer to the copy of the supplied string
  320.      or NULL if unsuccessful.
  321. *******************************************************************************/
  322. #ifdef PROTO
  323. CHARTYPE *my_strdup(CHARTYPE *str)
  324. #else
  325. CHARTYPE *my_strdup(str)
  326. CHARTYPE *str;
  327. #endif
  328. {
  329. /*--------------------------- local data ------------------------------*/
  330.  register short len=0;
  331.  register short  i = 0;
  332.  CHARTYPE *tmp;
  333. /*--------------------------- processing ------------------------------*/
  334.  len = strlen(str);
  335.  if ((tmp = (CHARTYPE *)(*the_malloc)((len+1)*sizeof(CHARTYPE))) == (CHARTYPE *)NULL)
  336.     return((CHARTYPE *)NULL);
  337.  strcpy(tmp,str);
  338.  return(tmp);
  339. }
  340. /*man***************************************************************************
  341. NAME
  342.      memne - search buffer for NOT character
  343.  
  344. SYNOPSIS
  345.      #include "the.h"
  346.  
  347.      short memne(buffer,chr,length)
  348.      CHARTYPE *buffer;
  349.      CHARTYPE chr;
  350.      short length;
  351.  
  352. DESCRIPTION
  353.      The memne function searches the buffer from the left for the first
  354.      character NOT equal to the supplied character.
  355.  
  356. RETURN VALUE
  357.      If successful, returns the position of first NON-matching character
  358.      or (-1) if unsuccessful.
  359.  
  360. SEE ALSO
  361.      strzrevne, memrevne, strzne
  362. *******************************************************************************/
  363. #ifdef PROTO
  364. short memne(CHARTYPE *buffer,CHARTYPE chr,short length)
  365. #else
  366. short memne(buffer,chr,length)
  367. CHARTYPE *buffer;
  368. CHARTYPE chr;
  369. short length;
  370. #endif
  371. {
  372. /*--------------------------- local data ------------------------------*/
  373.  register short  i = 0;
  374. /*--------------------------- processing ------------------------------*/
  375.  for (; i<length && buffer[i]==chr; i++);
  376.  if (i>=length)
  377.     i = (-1);
  378.  return(i);
  379. }
  380. /*man***************************************************************************
  381. NAME
  382.      strzrevne - search string reversed for NOT character
  383.  
  384. SYNOPSIS
  385.      #include "the.h"
  386.  
  387.      short strzrevne(str,chr)
  388.      CHARTYPE *str;
  389.      CHARTYPE ch;
  390.  
  391. DESCRIPTION
  392.      The strzrevne function searches the string from the right for the
  393.      first character NOT equal to the supplied character.
  394.  
  395. RETURN VALUE
  396.      If successful, returns the position of first NON-matching character
  397.      or (-1) if unsuccessful.
  398.  
  399. SEE ALSO
  400.      strzne, memrevne
  401. *******************************************************************************/
  402. #ifdef PROTO
  403. short strzrevne(CHARTYPE *str,CHARTYPE ch)
  404. #else
  405. short strzrevne(str,ch)
  406. CHARTYPE *str;
  407. CHARTYPE ch;
  408. #endif
  409. {
  410. /*--------------------------- local data ------------------------------*/
  411.  register short len=0;
  412. /*--------------------------- processing ------------------------------*/
  413.  len = strlen(str);
  414.  for (--len; len>=0 && str[len]==ch; len--);
  415.  return(len);
  416. }
  417. /*man***************************************************************************
  418. NAME
  419.      strzreveq - search string reversed for character
  420.  
  421. SYNOPSIS
  422.      short strzreveq(str,chr)
  423.      CHARTYPE *str;
  424.      CHARTYPE ch;
  425.  
  426. DESCRIPTION
  427.      The strzreveq function searches the string from the right for the
  428.      first character equal to the supplied character.
  429.  
  430. RETURN VALUE
  431.      If successful, returns the position of first matching character
  432.      or (-1) if unsuccessful.
  433.  
  434. SEE ALSO
  435.      strzrevne
  436. *******************************************************************************/
  437. #ifdef PROTO
  438. short strzreveq(CHARTYPE *str,CHARTYPE ch)
  439. #else
  440. short strzreveq(str,ch)
  441. CHARTYPE *str,ch;
  442. #endif
  443. /***********************************************************************/
  444. {
  445. /*--------------------------- local data ------------------------------*/
  446.  register short len=0;
  447. /*--------------------------- processing ------------------------------*/
  448.  len = strlen(str);
  449.  for (--len; len>=0 && str[len]!=ch; len--);
  450.  return(len);
  451. }
  452. /*man***************************************************************************
  453. NAME
  454.      strtrunc - truncate leading and trailing spaces from string
  455.  
  456. SYNOPSIS
  457.      #include "the.h"
  458.  
  459.      CHARTYPE *strtrunc(string)
  460.      CHARTYPE *string;
  461.  
  462. DESCRIPTION
  463.      The strtrunc truncates all leading and trailing spaces from
  464.      the supplied string.
  465.  
  466. RETURN VALUE
  467.      A pointer to the original string, now truncated.
  468.  
  469. SEE ALSO
  470.  
  471. *******************************************************************************/
  472. #ifdef PROTO
  473. CHARTYPE *strtrunc(CHARTYPE *string)
  474. #else
  475. CHARTYPE *strtrunc(string)
  476. CHARTYPE *string;
  477. #endif
  478. {
  479. /*--------------------------- local data ------------------------------*/
  480.  register short i=0;
  481.  short pos=0;
  482. /*--------------------------- processing ------------------------------*/
  483.  pos = strzrevne(string,' ');
  484.  if (pos == (-1))
  485.     strcpy(string,"");
  486.  else
  487.     *(string+pos+1) = '\0';
  488.  pos = strzne(string,' ');
  489.  if (pos != (-1))
  490.    {
  491.     for (i=0;*(string+i)!='\0';i++)
  492.        *(string+i) = *(string+i+pos);
  493.     *(string+i) = '\0';
  494.    }
  495.  return(string);
  496. }
  497. /*man***************************************************************************
  498. NAME
  499.      memfind - finds a needle in a haystack respecting case and arbitrary
  500.                characters if set.
  501.  
  502. SYNOPSIS
  503.      short memfind(haystack,needle,hay_len,nee_len,case_ignore,arbsts,arb)
  504.      CHARTYPE *haystack;                            string to be searched
  505.      CHARTYPE *needle;        string to search for - may contain arbchars
  506.      short hay_len;                                    length of haystack
  507.      short nee_len;                                      length of needle
  508.      bool case_ignore;                      TRUE if search to ignore case
  509.      bool arbsts;          TRUE if need to check for arbitrary characters
  510.      CHARTYPE single                       the single arbitrary character
  511.      CHARTYPE multiple                   the multiple arbitrary character
  512.  
  513. DESCRIPTION
  514.      The memfind function locates a needle in a haystack. Both the needle
  515.      and haystack may contain null characters. If case_ignore is TRUE,
  516.      then upper and lower case characters are treated equal. If arbsts
  517.      is ON, any arbitrary character, specified by arb, in needle, will
  518.      match ANY character in the haystack.
  519.  
  520. RETURN VALUE
  521.      The first occurrence (0 based) of needle in haystack, or (-1) if
  522.      the needle does not appear in the haystack.
  523. *******************************************************************************/
  524. #ifdef PROTO
  525. short memfind(CHARTYPE *haystack,CHARTYPE *needle,short hay_len,short nee_len,
  526.             bool case_ignore,bool arbsts,CHARTYPE arb_single,CHARTYPE arb_multiple)
  527. #else
  528. short memfind(haystack,needle,hay_len,nee_len,case_ignore,arbsts,arb_single,arb_multiple)
  529. CHARTYPE *haystack;
  530. CHARTYPE *needle;
  531. short hay_len;
  532. short nee_len;
  533. bool case_ignore;
  534. bool arbsts;
  535. CHARTYPE arb_single;
  536. CHARTYPE arb_multiple;
  537. #endif
  538. /*--------------------------- local data ------------------------------*/
  539. {
  540.  register CHARTYPE c1=0,c2=0;
  541.  register CHARTYPE *buf1,*buf2;
  542.  register short i=0,j=0;
  543.  short matches=0;
  544. /*--------------------------- processing ------------------------------*/
  545.  for (i=0;i<(hay_len-nee_len+1);i++)
  546.     {
  547.      buf1 = haystack+i;
  548.      buf2 = needle;
  549.      matches=0;
  550.      for (j=0;j<nee_len;j++)
  551.         {
  552.          if (case_ignore)
  553.            {
  554.             if (isupper(*buf1))
  555.                c1 = tolower(*buf1);
  556.             else
  557.                c1 = *buf1;
  558.             if (isupper(*buf2))
  559.                c2 = tolower(*buf2);
  560.             else
  561.                c2 = *buf2;
  562.            }
  563.          else
  564.            {
  565.             c1 = *buf1;
  566.             c2 = *buf2;
  567.            }
  568.          if (arbsts)
  569.            {
  570.             if (c1 != c2 && c2 != arb_single)
  571.                break;
  572.             else
  573.                matches++;
  574.            }
  575.          else
  576.            {
  577.             if (c1 != c2)
  578.                break;
  579.             else
  580.                matches++;
  581.            }
  582.          ++buf1;
  583.          ++buf2;
  584.         }
  585.      if (matches == nee_len)
  586.         return(i);
  587.     }
  588.  return(-1);
  589. }
  590. /***********************************************************************/
  591. #ifdef PROTO
  592. short memcmpi(CHARTYPE *buf1,CHARTYPE *buf2,short len)
  593. #else
  594. short memcmpi(buf1,buf2,len)
  595. CHARTYPE *buf1,*buf2;
  596. short len;
  597. #endif
  598. /***********************************************************************/
  599. /* Function  : Compares two memory buffers for equality;               */
  600. /*             case insensitive. Same as memicmp() Microsoft C.        */
  601. /* Parameters: buf1     - first buffer                                 */
  602. /*             buf2     - second buffer                                */
  603. /*             len      - number of characters to compare.             */
  604. /* Return    : <0 if buf1 < buf2,                                      */
  605. /*             =0 if buf1 = buf2,                                      */
  606. /*             >0 if buf1 > buf2,                                      */
  607. /***********************************************************************/
  608. {
  609. /*--------------------------- local data ------------------------------*/
  610.  register short i=0;
  611. /*--------------------------- processing ------------------------------*/
  612.  for(i=0;i<len;i++)
  613.    {
  614.     CHARTYPE c1,c2;
  615.     if (isupper(*buf1))
  616.        c1 = tolower(*buf1);
  617.     else
  618.        c1 = *buf1;
  619.     if (isupper(*buf2))
  620.        c2 = tolower(*buf2);
  621.     else
  622.        c2 = *buf2;
  623.     if (c1 != c2)
  624.        return(c1-c2);
  625.     ++buf1;
  626.     ++buf2;
  627.    }
  628.  return(0);
  629. }
  630. /***********************************************************************/
  631. #ifdef PROTO
  632. CHARTYPE *make_upper(CHARTYPE *str)
  633. #else
  634. CHARTYPE *make_upper(str)
  635. CHARTYPE *str;
  636. #endif
  637. /***********************************************************************/
  638. /* Function  : Makes the supplied string uppercase.                    */
  639. /*             Equivalent to strupr() on some platforms.      .        */
  640. /* Parameters: str      - string to uppercase                          */
  641. /* Return    : str uppercased                                          */
  642. /***********************************************************************/
  643. {
  644. /*--------------------------- local data ------------------------------*/
  645. /*--------------------------- processing ------------------------------*/
  646.  while(*str)
  647.    {
  648.     if (islower(*str))
  649.        *str = toupper(*str);
  650.     ++str;
  651.    }
  652.  return(str);
  653. }
  654. /*man***************************************************************************
  655. NAME
  656.      equal - determine if strings are equal up to specified length
  657.  
  658. SYNOPSIS
  659.      unsigned short equal(con,str,min_len)
  660.      CHARTYPE *con,*str;
  661.      short min_len;
  662.  
  663. DESCRIPTION
  664.      The equal function determines if a two strings are equal, irrespective
  665.      of case, up to the length of the second string. The length of the
  666.      second string must be greater than or equal to the specified minimum
  667.      length for the strings to be considered equal.
  668.  
  669. RETURN VALUE
  670.      If 'equal' TRUE else FALSE.
  671. *******************************************************************************/
  672. #ifdef PROTO
  673. unsigned short equal(CHARTYPE *con,CHARTYPE *str,short min_len)
  674. #else
  675. unsigned short equal(con,str,min_len)
  676. CHARTYPE *con,*str;
  677. short min_len;
  678. #endif
  679. {
  680. /*--------------------------- local data ------------------------------*/
  681. /*--------------------------- processing ------------------------------*/
  682. #ifdef TRACE
  683.  trace_function("util.c:    equal");
  684. #endif
  685.  if (min_len == 0)
  686.    {
  687. #ifdef TRACE
  688.     trace_return();
  689. #endif
  690.     return(FALSE);
  691.    }
  692.  if (memfind(con,str,min(strlen(str),strlen(con)),
  693.      min(strlen(str),strlen(con)),TRUE,FALSE,'\0','\0') == 0
  694.  &&  strlen(str) >= min_len
  695.  &&  strlen(con) >= strlen(str))
  696.    {
  697. #ifdef TRACE
  698.     trace_return();
  699. #endif
  700.     return(TRUE);
  701.    }
  702. #ifdef TRACE
  703.  trace_return();
  704. #endif
  705.  return(FALSE);
  706. }
  707. /***********************************************************************/
  708. #ifdef PROTO
  709. short valid_integer(CHARTYPE *str)
  710. #else
  711. short valid_integer(str)
  712. CHARTYPE *str;
  713. #endif
  714. /***********************************************************************/
  715. /* Function  : Checks that string contains only 0-9,- or +.            */
  716. /* Parameters: *str     - string to be checked                         */
  717. /* Return    : TRUE or FALSE                                           */
  718. /***********************************************************************/
  719. {
  720. /*--------------------------- local data ------------------------------*/
  721.  register short i=0;
  722.  short num_signs=0;
  723. /*--------------------------- processing ------------------------------*/
  724. #ifdef TRACE
  725.  trace_function("util.c:    valid_integer");
  726. #endif
  727.  for (i=0; i<strlen(str); i++)
  728.     {
  729.      if (*(str+i) == '-' || *(str+i) == '+')
  730.         num_signs++;
  731.      else
  732.         if (!isdigit(*(str+i)))
  733.           {
  734. #ifdef TRACE
  735.            trace_return();
  736. #endif
  737.            return(FALSE);
  738.           }
  739.     }
  740.  if (num_signs > 1)
  741.    {
  742. #ifdef TRACE
  743.     trace_return();
  744. #endif
  745.     return(FALSE);
  746.    }
  747. #ifdef TRACE
  748.  trace_return();
  749. #endif
  750.  return(TRUE);
  751. }
  752. /***********************************************************************/
  753. #ifdef PROTO
  754. short valid_positive_integer(CHARTYPE *str)
  755. #else
  756. short valid_positive_integer(str)
  757. CHARTYPE *str;
  758. #endif
  759. /***********************************************************************/
  760. /* Function  : Checks that string contains only 0-9, or +.             */
  761. /* Parameters: *str     - string to be checked                         */
  762. /* Return    : TRUE or FALSE                                           */
  763. /***********************************************************************/
  764. {
  765. /*--------------------------- local data ------------------------------*/
  766.  register short i=0;
  767.  short num_signs=0;
  768. /*--------------------------- processing ------------------------------*/
  769. #ifdef TRACE
  770.  trace_function("util.c:    valid_positive_integer");
  771. #endif
  772.  for (i=0; i<strlen(str); i++)
  773.     {
  774.      if (*(str+i) == '+')
  775.         num_signs++;
  776.      else
  777.         if (!isdigit(*(str+i)))
  778.           {
  779. #ifdef TRACE
  780.            trace_return();
  781. #endif
  782.            return(FALSE);
  783.           }
  784.     }
  785.  if (num_signs > 1)
  786.    {
  787. #ifdef TRACE
  788.     trace_return();
  789. #endif
  790.     return(FALSE);
  791.    }
  792. #ifdef TRACE
  793.  trace_return();
  794. #endif
  795.  return(TRUE);
  796. }
  797. /***********************************************************************/
  798. #ifdef PROTO
  799. short strzeq(CHARTYPE *str,CHARTYPE ch)
  800. #else
  801. short strzeq(str,ch)
  802. CHARTYPE *str;
  803. CHARTYPE ch;
  804. #endif
  805. /***********************************************************************/
  806. /* Function  : Locate in ASCIIZ string, character                      */
  807. /* Parameters: *str     - string to be searched                        */
  808. /*             ch       - character to be searched for                 */
  809. /* Return    : position in string of character - (-1) if not found     */
  810. /***********************************************************************/
  811. {
  812. /*--------------------------- local data ------------------------------*/
  813.  register short len=0;
  814.  register short  i = 0;
  815. /*--------------------------- processing ------------------------------*/
  816.  len = strlen(str);
  817.  for (; i<len && str[i]!=ch; i++);
  818.  if (i>=len)
  819.     i = (-1);
  820.  return(i);
  821. }
  822.  
  823. /***********************************************************************/
  824. #ifdef PROTO
  825. CHARTYPE *strtrans(CHARTYPE *str,CHARTYPE oldch,CHARTYPE newch)
  826. #else
  827. CHARTYPE *strtrans(str,oldch,newch)
  828. CHARTYPE *str;
  829. CHARTYPE oldch,newch;
  830. #endif
  831. /***********************************************************************/
  832. /* Function  : Translate all occurrences of oldch to newch in str      */
  833. /* Parameters: *str     - string to be amendedd                        */
  834. /*             oldch    - character to be replaced                     */
  835. /*             newch    - character to replace oldch                   */
  836. /* Return    : same string but with characters translated              */
  837. /***********************************************************************/
  838. {
  839. /*--------------------------- local data ------------------------------*/
  840.  register short len=0;
  841.  register short  i=0;
  842. /*--------------------------- processing ------------------------------*/
  843.  len = strlen(str);
  844.  for (i=0;i<strlen(str); i++)
  845.    {
  846.     if (*(str+i) == oldch)
  847.        *(str+i) = newch;
  848.    }
  849.  return(str);
  850. }
  851.  
  852. /***********************************************************************/
  853. #ifdef PROTO
  854. LINE *add_line(LINE *first,LINE *curr,CHARTYPE *line,
  855.                LENGTHTYPE len,SELECTTYPE select)
  856. #else
  857. LINE *add_line(first,curr,line,len,select)
  858. LINE *first;
  859. LINE *curr;
  860. CHARTYPE *line;
  861. LENGTHTYPE len;
  862. SELECTTYPE select;
  863. #endif
  864. /***********************************************************************/
  865. /* Adds a member of the linked list for the specified file containing  */
  866. /* the line contents and length.                                       */
  867. /* PARAMETERS:                                                         */
  868. /* first      - pointer to first line for the file                     */
  869. /* curr       - pointer to current line for the file                   */
  870. /* line       - contents of line to be added                           */
  871. /* len        - length of line to be added                             */
  872. /* select     - select level of new line                               */
  873. /* RETURN:    - pointer to current item in linked list or NULL if error*/
  874. /***********************************************************************/
  875. {
  876. /*-------------------------- external data ----------------------------*/
  877.  extern LINE *curr_line;
  878.  extern LINE *next_line;
  879. /*--------------------------- local data ------------------------------*/
  880. /*--------------------------- processing ------------------------------*/
  881. #ifdef TRACE
  882.  trace_function("util.c:    add_line");
  883. #endif
  884.  next_line = lll_add(first,curr,sizeof(LINE));
  885.  if (next_line == NULL)
  886.    {
  887. #ifdef TRACE
  888.     trace_return();
  889. #endif
  890.     return(NULL);
  891.    }
  892.  curr_line = next_line;
  893.  
  894.  curr_line->line = (CHARTYPE *)(*the_malloc)((len+1)*sizeof(CHARTYPE));
  895.  if (curr_line->line == NULL)
  896.    {
  897. #ifdef TRACE
  898.     trace_return();
  899. #endif
  900.     return(NULL);
  901.    }
  902.  memcpy(curr_line->line,line,len);
  903.  *(curr_line->line+len) = '\0'; /* for functions that expect ASCIIZ string */
  904.  curr_line->length = len;
  905.  curr_line->select = select;
  906.  curr_line->pre = NULL;
  907.  curr_line->name = NULL;
  908. #ifdef TRACE
  909.  trace_return();
  910. #endif
  911.  return(curr_line);
  912. }
  913. /***********************************************************************/
  914. #ifdef PROTO
  915. LINE *delete_line(LINE *first,LINE *curr,short direction)
  916. #else
  917. LINE *delete_line(first,curr,direction)
  918. LINE *first,*curr;
  919. short direction;
  920. #endif
  921. /***********************************************************************/
  922. /* Deletes a member of the linked list for the specified file.         */
  923. /* PARAMETERS:                                                         */
  924. /* first      - pointer to first line for the file                     */
  925. /* curr       - pointer to current line for the file                   */
  926. /* direction  - direction in which to delete.                          */
  927. /* RETURN:    - pointer to current item in linked list or NULL if error*/
  928. /***********************************************************************/
  929. {
  930. /*--------------------------- local data ------------------------------*/
  931. /*--------------------------- processing ------------------------------*/
  932. #ifdef TRACE
  933.  trace_function("util.c:    delete_line");
  934. #endif
  935.  if (curr->name != (CHARTYPE *)NULL)
  936.     (*the_free)(curr->name);
  937.  (*the_free)(curr->line);
  938.  curr = lll_del(&first,NULL,curr,direction);
  939. #ifdef TRACE
  940.  trace_return();
  941. #endif
  942.  return(curr);
  943. }
  944.  
  945. /***********************************************************************/
  946. #ifdef PROTO
  947. void put_string(WINDOW *win,short row,short col,CHARTYPE *string,short len)
  948. #else
  949. void put_string(win,row,col,string,len)
  950. WINDOW *win;
  951. short row,col;
  952. CHARTYPE *string;
  953. short len;
  954. #endif
  955. /***********************************************************************/
  956. {
  957. /*--------------------------- local data ------------------------------*/
  958.  register short i=0;
  959. /*--------------------------- processing ------------------------------*/
  960. #ifdef TRACE
  961.  trace_function("util.c:    put_string");
  962. #endif
  963.  wmove(win,row,col);
  964.  for (i=0;i<len;i++)
  965.    {
  966.     put_char(win,*(string+i),ADDCHAR);
  967.    }
  968. #ifdef TRACE
  969.  trace_return();
  970. #endif
  971.  return;
  972. }
  973. /***********************************************************************/
  974. #ifdef PROTO
  975. void put_char(WINDOW *win,chtype ch,CHARTYPE add_ins)
  976. #else
  977. void put_char(win,ch,add_ins)
  978. WINDOW *win;
  979. chtype ch;
  980. CHARTYPE add_ins;
  981. #endif
  982. /***********************************************************************/
  983. {
  984. /*------------------------- external data -----------------------------*/
  985.  extern CHARTYPE NONDISPx;
  986.  extern short compatible;
  987.  extern bool ETMODEx;
  988. /*--------------------------- local data ------------------------------*/
  989.  chtype chr_attr=0,chr=0,attr=0;
  990. /*--------------------------- processing ------------------------------*/
  991. #ifdef TRACE
  992.  trace_function("util.c:    put_char");
  993. #endif
  994.  chr_attr = ch;
  995.  
  996.  if (!ETMODEx)
  997.    {
  998.     chr = chr_attr & A_CHARTEXT;
  999.     if (chr > 126 || chr < 32)
  1000.       {
  1001.        switch(compatible)
  1002.          {
  1003.           case COMPAT_THE:
  1004.           case COMPAT_KEDIT:
  1005.                attr = (~chr_attr) & A_ATTRIBUTES & ~A_ALTCHARSET;
  1006.                if (chr > 126)
  1007.                   chr_attr = NONDISPx | attr;
  1008.                else
  1009.                   if (chr < 32)
  1010.                chr_attr = ('@' + chr) | attr;
  1011.                break;
  1012.           case COMPAT_XEDIT:
  1013.                attr = chr_attr & A_ATTRIBUTES;
  1014.                chr_attr = NONDISPx | attr;
  1015.                break;
  1016.          }
  1017.       }
  1018.    }
  1019.  
  1020.  if (add_ins == ADDCHAR)
  1021.     waddch(win,chr_attr);
  1022.  else
  1023.     winsch(win,chr_attr);
  1024. #ifdef TRACE
  1025.  trace_return();
  1026. #endif
  1027.  return;
  1028. }
  1029. /***********************************************************************/
  1030. #ifdef PROTO
  1031. short set_up_windows(short scrn)
  1032. #else
  1033. short set_up_windows(scrn)
  1034. short scrn;
  1035. #endif
  1036. /***********************************************************************/
  1037. {
  1038. /*-------------------------- external data ----------------------------*/
  1039.  extern bool curses_started;
  1040.  extern short prefix_width;
  1041.  extern CHARTYPE display_screens;
  1042.  extern bool horizontal;
  1043.  extern WINDOW *divider;
  1044. /*--------------------------- local data ------------------------------*/
  1045.  register short i=0;
  1046.  CHARTYPE command_location=0;
  1047.  short y=0,x=0;
  1048. /*--------------------------- processing ------------------------------*/
  1049. #ifdef TRACE
  1050.  trace_function("util.c:    set_up_windows");
  1051. #endif
  1052. /*---------------------------------------------------------------------*/
  1053. /* If curses has not started exit gracefully...                        */
  1054. /*---------------------------------------------------------------------*/
  1055.  if (!curses_started)
  1056.    {
  1057. #ifdef TRACE
  1058.     trace_return();
  1059. #endif
  1060.     return(RC_OK);
  1061.    }
  1062. /*---------------------------------------------------------------------*/
  1063. /* Save the position of the cursor in each window, and then delete the */
  1064. /* window. Recreate each window, that has a valid size and move the    */
  1065. /* cursor back to the position it had in each window.                  */
  1066. /*---------------------------------------------------------------------*/
  1067.  for (i=0;i<VIEW_WINDOWS;i++)
  1068.    {
  1069.     y = x = 0;
  1070.     if (screen[scrn].win[i] != (WINDOW *)NULL)
  1071.       {
  1072.        getyx(screen[scrn].win[i],y,x);
  1073.        delwin(screen[scrn].win[i]);
  1074.        screen[scrn].win[i] = (WINDOW *)NULL;
  1075.       }
  1076.     if (screen[scrn].rows[i] != 0
  1077.     &&  screen[scrn].cols[i] != 0)
  1078.       {
  1079.        screen[scrn].win[i] = newwin(screen[scrn].rows[i],screen[scrn].cols[i],
  1080.                                  screen[scrn].start_row[i],screen[scrn].start_col[i]);
  1081.        if (screen[scrn].win[i] == (WINDOW *)NULL)
  1082.          {
  1083.           display_error(30,(CHARTYPE *)"creating window",FALSE);
  1084. #ifdef TRACE
  1085.           trace_return();
  1086. #endif
  1087.           return(RC_OUT_OF_MEMORY);
  1088.          }
  1089.        wmove(screen[scrn].win[i],y,x);
  1090.       }
  1091.     }
  1092.  wattrset(screen[scrn].win[WINDOW_MAIN],set_colour(screen[scrn].screen_view->file_for_view->attr+ATTR_FILEAREA));
  1093.  
  1094.  if (screen[scrn].win[WINDOW_ARROW] != (WINDOW *)NULL)
  1095.    {
  1096.     wattrset(screen[scrn].win[WINDOW_ARROW],set_colour(screen[scrn].screen_view->file_for_view->attr+ATTR_ARROW));
  1097.     mvwaddstr(screen[scrn].win[WINDOW_ARROW],0,0,"====> ");
  1098.     wnoutrefresh(screen[scrn].win[WINDOW_ARROW]);
  1099.    }
  1100.  
  1101.  if (screen[scrn].win[WINDOW_IDLINE] != (WINDOW *)NULL)
  1102.    {
  1103.     wattrset(screen[scrn].win[WINDOW_IDLINE],set_colour(screen[scrn].screen_view->file_for_view->attr+ATTR_IDLINE));
  1104.     wmove(screen[scrn].win[WINDOW_IDLINE],0,0);
  1105.     my_wclrtoeol(screen[scrn].win[WINDOW_IDLINE]);
  1106.    }
  1107.  
  1108.  if (screen[scrn].win[WINDOW_PREFIX] != (WINDOW *)NULL)
  1109.     wattrset(screen[scrn].win[WINDOW_PREFIX],set_colour(screen[scrn].screen_view->file_for_view->attr+ATTR_PENDING));
  1110.  
  1111.  if (screen[scrn].win[WINDOW_COMMAND] != (WINDOW *)NULL)
  1112.    {
  1113.     wattrset(screen[scrn].win[WINDOW_COMMAND],set_colour(screen[scrn].screen_view->file_for_view->attr+ATTR_CMDLINE));
  1114.     wmove(screen[scrn].win[WINDOW_COMMAND],0,0);
  1115.     my_wclrtoeol(screen[scrn].win[WINDOW_COMMAND]);
  1116.     wnoutrefresh(screen[scrn].win[WINDOW_COMMAND]);
  1117.     wmove(screen[scrn].win[WINDOW_COMMAND],0,0);
  1118.    }
  1119. /*---------------------------------------------------------------------*/
  1120. /* Set up divider window...                                            */
  1121. /*---------------------------------------------------------------------*/
  1122.  if (display_screens > 1
  1123.  &&  !horizontal)
  1124.    {
  1125.     if (divider != (WINDOW *)NULL)
  1126.        delwin(divider);
  1127.     divider = newwin(screen[1].screen_rows,2,screen[1].screen_start_row,
  1128.                      screen[1].screen_start_col-2);
  1129.     if (divider == (WINDOW *)NULL)
  1130.       {
  1131.        display_error(30,(CHARTYPE *)"creating window",FALSE);
  1132. #ifdef TRACE
  1133.        trace_return();
  1134. #endif
  1135.        return(RC_OUT_OF_MEMORY);
  1136.       }
  1137. #ifdef A_ALTCHARSET
  1138.     wattrset(divider,A_ALTCHARSET|set_colour(CURRENT_FILE->attr+ATTR_DIVIDER));
  1139. #else
  1140.     wattrset(divider,set_colour(CURRENT_FILE->attr+ATTR_DIVIDER));
  1141. #endif
  1142.     for (i=0;i<screen[1].screen_rows;i++)
  1143.       {
  1144.        wmove(divider,i,0);
  1145. #ifdef ACS_VLINE
  1146.        waddch(divider,ACS_VLINE);
  1147.        waddch(divider,ACS_VLINE);
  1148. #else
  1149.        waddch(divider,' ');
  1150.        waddch(divider,' ');
  1151. #endif
  1152.       }
  1153.    }
  1154. #ifdef TRACE
  1155.  trace_return();
  1156. #endif
  1157.  return(RC_OK);
  1158. }
  1159. /***********************************************************************/
  1160. #ifdef PROTO
  1161. short create_statusline_window(void)
  1162. #else
  1163. short create_statusline_window()
  1164. #endif
  1165. /***********************************************************************/
  1166. {
  1167. /*-------------------------- external data ----------------------------*/
  1168.  extern bool curses_started;
  1169.  extern ROWTYPE STATUSLINEx;
  1170.  extern WINDOW *foot;
  1171. /*--------------------------- local data ------------------------------*/
  1172. /*--------------------------- processing ------------------------------*/
  1173. #ifdef TRACE
  1174.  trace_function("util.c:    create_statusline_window");
  1175. #endif
  1176.  if (!curses_started)
  1177.    {
  1178. #ifdef TRACE
  1179.     trace_return();
  1180. #endif
  1181.     return(RC_OK);
  1182.    }
  1183.  if (foot != (WINDOW *)NULL)
  1184.    {
  1185.     delwin(foot);
  1186.     foot = (WINDOW *)NULL;
  1187.    }
  1188.  switch(STATUSLINEx)
  1189.    {
  1190.     case 'B':
  1191.          foot = newwin(1,COLS,LINES-1,0);
  1192.          wattrset(foot,set_colour(CURRENT_FILE->attr+ATTR_STATAREA));
  1193.          clear_footing();
  1194.          break;
  1195.     case 'T':
  1196.          foot = newwin(1,COLS,0,0);
  1197.          wattrset(foot,set_colour(CURRENT_FILE->attr+ATTR_STATAREA));
  1198.          clear_footing();
  1199.          break;
  1200.     default:
  1201.          break;
  1202.    }
  1203. #ifdef TRACE
  1204.  trace_return();
  1205. #endif
  1206.  return(RC_OK);
  1207. }
  1208. /***********************************************************************/
  1209. #ifdef PROTO
  1210. void pre_process_line(VIEW_DETAILS *the_view,LINETYPE line_number)
  1211. #else
  1212. void pre_process_line(the_view,line_number)
  1213. VIEW_DETAILS *the_view;
  1214. LINETYPE line_number;
  1215. #endif
  1216. /***********************************************************************/
  1217. {
  1218. /*-------------------------- external data ----------------------------*/
  1219.  extern unsigned short pre_rec_len;
  1220.  extern CHARTYPE *pre_rec;
  1221.  extern LENGTHTYPE rec_len;
  1222.  extern CHARTYPE *rec;
  1223. /*--------------------------- local data ------------------------------*/
  1224.  LINE *curr=NULL;
  1225. /*--------------------------- processing ------------------------------*/
  1226. #ifdef TRACE
  1227.  trace_function("util.c:    pre_process_line");
  1228. #endif
  1229.  curr = lll_find(the_view->file_for_view->first_line,line_number);
  1230.  memset(rec,' ',max_line_length);
  1231.  memcpy(rec,curr->line,curr->length);
  1232.  rec_len = curr->length;
  1233. /*---------------------------------------------------------------------*/
  1234. /* Now set up the prefix command from the linked list...               */
  1235. /*---------------------------------------------------------------------*/
  1236.  if (curr->pre == NULL)
  1237.    {
  1238.     memset(pre_rec,' ',PREFIX_WIDTH);
  1239.     pre_rec_len = 0;
  1240.    }
  1241.  else
  1242.    {
  1243.     memset(pre_rec,' ',PREFIX_WIDTH);
  1244.     strcpy(pre_rec,curr->pre->ppc_command);
  1245.     pre_rec_len = strlen(pre_rec);
  1246.     pre_rec[pre_rec_len] = ' ';
  1247.     pre_rec[PREFIX_WIDTH] = '\0';
  1248.    }
  1249. #ifdef TRACE
  1250.  trace_return();
  1251. #endif
  1252.  return;
  1253. }
  1254. /***********************************************************************/
  1255. #ifdef PROTO
  1256. short post_process_line(VIEW_DETAILS *the_view,LINETYPE line_number)
  1257. #else
  1258. short post_process_line(the_view,line_number)
  1259. VIEW_DETAILS *the_view;
  1260. LINETYPE line_number;
  1261. #endif
  1262. /***********************************************************************/
  1263. {
  1264. /*------------------------- external data -----------------------------*/
  1265.  extern bool prefix_changed;
  1266.  extern CHARTYPE *rec;
  1267.  extern LENGTHTYPE rec_len;
  1268. /*--------------------------- local data ------------------------------*/
  1269.  LINE *curr=NULL;
  1270.  short rc=RC_OK;
  1271. /*--------------------------- processing ------------------------------*/
  1272. #ifdef TRACE
  1273.  trace_function("util.c:    post_process_line");
  1274. #endif
  1275. /*---------------------------------------------------------------------*/
  1276. /* Find the specified line in the linked list...                       */
  1277. /*---------------------------------------------------------------------*/
  1278.  curr = lll_find(the_view->file_for_view->first_line,line_number);
  1279. /*---------------------------------------------------------------------*/
  1280. /* First copy the pending prefix command to the linked list.           */
  1281. /* Only do it if the prefix command has a value or there is already a  */
  1282. /* pending prefix command for that line.                               */
  1283. /*---------------------------------------------------------------------*/
  1284.  if (prefix_changed)
  1285.     add_prefix_command(curr,line_number,FALSE);
  1286. /*---------------------------------------------------------------------*/
  1287. /* If the line hasn't changed, return.                                 */
  1288. /*---------------------------------------------------------------------*/
  1289.  if (rec_len == curr->length && (memcmp(rec,curr->line,curr->length) == 0))
  1290.    {
  1291. #ifdef TRACE
  1292.     trace_return();
  1293. #endif
  1294.     return(RC_OK);
  1295.    }
  1296. /*---------------------------------------------------------------------*/
  1297. /* Increment the alteration counters...                                */
  1298. /*---------------------------------------------------------------------*/
  1299.  if ((rc = increment_alt(the_view->file_for_view)) != RC_OK)
  1300.    {
  1301. #ifdef TRACE
  1302.     trace_return();
  1303. #endif
  1304.     return(rc);
  1305.    }
  1306. /*---------------------------------------------------------------------*/
  1307. /* Add the old line contents to the line recovery list.                */
  1308. /*---------------------------------------------------------------------*/
  1309.  add_to_recovery_list(curr->line,curr->length);
  1310. /*---------------------------------------------------------------------*/
  1311. /* Realloc the dynamic memory for the line if the line is now longer.  */
  1312. /*---------------------------------------------------------------------*/
  1313.  if (rec_len > curr->length)
  1314.    {
  1315.     curr->line = (CHARTYPE *)(*the_realloc)((void *)curr->line,(rec_len+1)*sizeof(CHARTYPE));
  1316.     if (curr->line == NULL)
  1317.       {
  1318.        display_error(30,"",FALSE);
  1319. #ifdef TRACE
  1320.        trace_return();
  1321. #endif
  1322.        return(RC_OUT_OF_MEMORY);
  1323.       }
  1324.    }
  1325. /*---------------------------------------------------------------------*/
  1326. /* Copy the contents of rec into the line.                             */
  1327. /*---------------------------------------------------------------------*/
  1328.  memcpy(curr->line,rec,rec_len);
  1329.  curr->length = rec_len;
  1330.  *(curr->line+rec_len) = '\0';
  1331. #ifdef TRACE
  1332.  trace_return();
  1333. #endif
  1334.  return(rc);
  1335. }
  1336. /***********************************************************************/
  1337. #ifdef PROTO
  1338. bool blank_field(CHARTYPE *field)
  1339. #else
  1340. bool blank_field(field)
  1341. CHARTYPE *field;
  1342. #endif
  1343. /***********************************************************************/
  1344. {
  1345. /*--------------------------- local data ------------------------------*/
  1346. /*--------------------------- processing ------------------------------*/
  1347. #ifdef TRACE
  1348.  trace_function("util.c:    blank_field");
  1349. #endif
  1350.  if (strzne(field,' ') == (-1))
  1351.    {
  1352. #ifdef TRACE
  1353.     trace_return();
  1354. #endif
  1355.     return(TRUE);                /* field is NULL or just contains spaces */
  1356.    }
  1357. #ifdef TRACE
  1358.  trace_return();
  1359. #endif
  1360.  return(FALSE);
  1361. }
  1362. /***********************************************************************/
  1363. #ifdef PROTO
  1364. void adjust_marked_lines(bool insert_line,LINETYPE base_line,LINETYPE num_lines)
  1365. #else
  1366. void adjust_marked_lines(insert_line,base_line,num_lines)
  1367. bool insert_line;
  1368. LINETYPE base_line;
  1369. LINETYPE num_lines;
  1370. #endif
  1371. /***********************************************************************/
  1372. {
  1373. /*---------------------------------------------------------------------*/
  1374. /* When lines are deleted, the base line is the first line in the file */
  1375. /* irrespective of the direction that the delete is done.              */
  1376. /*---------------------------------------------------------------------*/
  1377. /*-------------------------- external data ----------------------------*/
  1378.  extern VIEW_DETAILS *vd_mark;
  1379. /*--------------------------- local data ------------------------------*/
  1380. /*--------------------------- processing ------------------------------*/
  1381. #ifdef TRACE
  1382.  trace_function("util.c:    adjust_marked_lines");
  1383. #endif
  1384. /*---------------------------------------------------------------------*/
  1385. /* If there are no marked lines in the current view, return.           */
  1386. /*---------------------------------------------------------------------*/
  1387.  if (MARK_VIEW != CURRENT_VIEW)
  1388.    {
  1389. #ifdef TRACE
  1390.     trace_return();
  1391. #endif
  1392.     return;
  1393.    }
  1394.  switch(insert_line)
  1395.    {
  1396.     case TRUE:/* INSERT */
  1397.          if (base_line < CURRENT_VIEW->mark_start_line)
  1398.            {
  1399.             CURRENT_VIEW->mark_start_line += num_lines;
  1400.             CURRENT_VIEW->mark_end_line += num_lines;
  1401.             break;
  1402.            }
  1403.          if (base_line >= CURRENT_VIEW->mark_start_line
  1404.          &&  base_line < CURRENT_VIEW->mark_end_line)
  1405.            {
  1406.             CURRENT_VIEW->mark_end_line += num_lines;
  1407.             break;
  1408.            }
  1409.          break;
  1410.     case FALSE:  /* DELETE */
  1411.          if (base_line <= CURRENT_VIEW->mark_start_line
  1412.          &&  base_line+num_lines-1L >= CURRENT_VIEW->mark_end_line)
  1413.            {
  1414.             CURRENT_VIEW->marked_line = FALSE;
  1415.             MARK_VIEW = (VIEW_DETAILS *)NULL;
  1416.             break;
  1417.            }
  1418.          if (base_line+num_lines-1L < CURRENT_VIEW->mark_start_line)
  1419.            {
  1420.             CURRENT_VIEW->mark_start_line -= num_lines;
  1421.             CURRENT_VIEW->mark_end_line -= num_lines;
  1422.             break;
  1423.            }
  1424.          if (base_line > CURRENT_VIEW->mark_end_line)
  1425.            {
  1426.             break;
  1427.            }
  1428.          if (base_line+num_lines-1L > CURRENT_VIEW->mark_end_line)
  1429.            {
  1430.             CURRENT_VIEW->mark_end_line = base_line - 1L;
  1431.             break;
  1432.            }
  1433.          if (base_line < CURRENT_VIEW->mark_start_line)
  1434.            {
  1435.             CURRENT_VIEW->mark_start_line = base_line;
  1436.             CURRENT_VIEW->mark_end_line = base_line +
  1437.                                          (CURRENT_VIEW->mark_end_line -
  1438.                                           (base_line + num_lines));
  1439.             break;
  1440.            }
  1441.          CURRENT_VIEW->mark_end_line -= num_lines;
  1442.          break;
  1443.    }
  1444. #ifdef TRACE
  1445.  trace_return();
  1446. #endif
  1447.  return;
  1448. }
  1449. /***********************************************************************/
  1450. #ifdef PROTO
  1451. void adjust_pending_prefix(VIEW_DETAILS *view,bool insert_line,LINETYPE base_line,LINETYPE num_lines)
  1452. #else
  1453. void adjust_pending_prefix(view,insert_line,base_line,num_lines)
  1454. VIEW_DETAILS *view;
  1455. bool insert_line;
  1456. LINETYPE base_line;
  1457. LINETYPE num_lines;
  1458. #endif
  1459. /***********************************************************************/
  1460. {
  1461. /*---------------------------------------------------------------------*/
  1462. /* When lines are deleted, the base line is the first line in the file */
  1463. /* irrespective of the direction that the delete is done.              */
  1464. /*---------------------------------------------------------------------*/
  1465. /*--------------------------- local data ------------------------------*/
  1466.  register short i=0;
  1467.  PPC *curr_ppc=NULL;
  1468. /*--------------------------- processing ------------------------------*/
  1469. #ifdef TRACE
  1470.  trace_function("util.c:    adjust_pending_prefix");
  1471. #endif
  1472. /*---------------------------------------------------------------------*/
  1473. /* If there are no pending prefix commands in the view, return.        */
  1474. /*---------------------------------------------------------------------*/
  1475.  if (view->file_for_view->first_ppc == NULL)
  1476.    {
  1477. #ifdef TRACE
  1478.     trace_return();
  1479. #endif
  1480.     return;
  1481.    }
  1482.  curr_ppc = view->file_for_view->first_ppc;
  1483.  while (curr_ppc != NULL)
  1484.    {
  1485.     switch(insert_line)
  1486.       {
  1487.        case TRUE:/* INSERT */
  1488.             if (base_line < curr_ppc->ppc_line_number)
  1489.               {
  1490.                curr_ppc->ppc_line_number += num_lines;
  1491.                break;
  1492.               }
  1493.             break;
  1494.        case FALSE:  /* DELETE */
  1495.             if (base_line+num_lines-1L < curr_ppc->ppc_line_number)
  1496.               {
  1497.                curr_ppc->ppc_line_number -= num_lines;
  1498.                break;
  1499.               }
  1500.             if (base_line > curr_ppc->ppc_line_number)
  1501.                break;
  1502. #if OLD_CLEAR
  1503.             (void)delete_pending_prefix_command(curr_ppc,view->file_for_view,(LINE *)NULL);
  1504. #else
  1505.             clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1506. #endif
  1507.             break;
  1508.       }
  1509.     curr_ppc = curr_ppc->next;
  1510.    }
  1511. #ifdef TRACE
  1512.  trace_return();
  1513. #endif
  1514.  return;
  1515. }
  1516. /***********************************************************************/
  1517. #ifdef PROTO
  1518. CHARTYPE case_translate(CHARTYPE key)
  1519. #else
  1520. CHARTYPE case_translate(key)
  1521. CHARTYPE key;
  1522. #endif
  1523. /***********************************************************************/
  1524. {
  1525. /*-------------------------- external data ----------------------------*/
  1526. /*--------------------------- local data ------------------------------*/
  1527. /*--------------------------- processing ------------------------------*/
  1528. #ifdef TRACE
  1529.  trace_function("util.c:    case_translate");
  1530. #endif
  1531.  if (CURRENT_VIEW->case_enter == CASE_UPPER
  1532.  && islower(key))
  1533.    {
  1534. #ifdef TRACE
  1535.     trace_return();
  1536. #endif
  1537.     return(toupper(key));
  1538.    }
  1539.  if (CURRENT_VIEW->case_enter == CASE_LOWER
  1540.  && isupper(key))
  1541.    {
  1542. #ifdef TRACE
  1543.     trace_return();
  1544. #endif
  1545.     return(tolower(key));
  1546.    }
  1547. #ifdef TRACE
  1548.  trace_return();
  1549. #endif
  1550.  return(key);
  1551. }
  1552. /***********************************************************************/
  1553. #ifdef PROTO
  1554. void add_to_recovery_list(CHARTYPE *line,LENGTHTYPE len)
  1555. #else
  1556. void add_to_recovery_list(line,len)
  1557. CHARTYPE *line;
  1558. LENGTHTYPE len;
  1559. #endif
  1560. /***********************************************************************/
  1561. {
  1562. /*-------------------------- external data ----------------------------*/
  1563.  extern bool in_profile;
  1564. /*--------------------------- local data ------------------------------*/
  1565.  register short i=0;
  1566. /*--------------------------- processing ------------------------------*/
  1567. #ifdef TRACE
  1568.  trace_function("util.c:    add_to_recovery_list");
  1569. #endif
  1570. /*---------------------------------------------------------------------*/
  1571. /* Ignore if in profile.                                               */
  1572. /*---------------------------------------------------------------------*/
  1573.  if (in_profile)
  1574.    {
  1575. #ifdef TRACE
  1576.     trace_return();
  1577. #endif
  1578.     return;
  1579.    }
  1580. /*---------------------------------------------------------------------*/
  1581. /* Ignore empty lines.                                                 */
  1582. /*---------------------------------------------------------------------*/
  1583.  if (len == 0)
  1584.    {
  1585. #ifdef TRACE
  1586.     trace_return();
  1587. #endif
  1588.     return;
  1589.    }
  1590. /*---------------------------------------------------------------------*/
  1591. /* First time through, set line array to NULL,  to indicated unused.   */
  1592. /* This setup MUST occur before the freeing up code.                   */
  1593. /*---------------------------------------------------------------------*/
  1594.  if (add_recv == (-1))
  1595.    {
  1596.     for (i=0;i<MAX_RECV;i++)
  1597.        recv[i] = NULL;
  1598.     add_recv = 0;               /* set to point to next available slot */
  1599.    }
  1600. /*---------------------------------------------------------------------*/
  1601. /* Now we are here, lets add to the array.                             */
  1602. /*---------------------------------------------------------------------*/
  1603.  if (recv[add_recv] == NULL)  /* haven't malloced yet */
  1604.    {
  1605.     if ((recv[add_recv] = (CHARTYPE *)(*the_malloc)((len+1)*sizeof(CHARTYPE))) == NULL)
  1606.       {
  1607.        display_error(30,(CHARTYPE *)"",FALSE);
  1608. #ifdef TRACE
  1609.        trace_return();
  1610. #endif
  1611.        return;
  1612.       }
  1613.    }
  1614.  else
  1615.    {
  1616.     if ((recv[add_recv] = (CHARTYPE *)(*the_realloc)(recv[add_recv],(len+1)*sizeof(CHARTYPE))) == NULL)
  1617.       {
  1618.        display_error(30,(CHARTYPE *)"",FALSE);
  1619. #ifdef TRACE
  1620.        trace_return();
  1621. #endif
  1622.        return;
  1623.       }
  1624.    }
  1625.  memcpy(recv[add_recv],line,len);
  1626.  recv_len[add_recv] = len;
  1627.  retr_recv = add_recv;
  1628.  add_recv = (++add_recv >= MAX_RECV) ? 0 : add_recv;
  1629.  num_recv = (++num_recv > MAX_RECV) ? MAX_RECV : num_recv;
  1630.  
  1631. #ifdef TRACE
  1632.  trace_return();
  1633. #endif
  1634.  return;
  1635. }
  1636. /***********************************************************************/
  1637. #ifdef PROTO
  1638. void get_from_recovery_list(short num)
  1639. #else
  1640. void get_from_recovery_list(num)
  1641. short num;
  1642. #endif
  1643. /***********************************************************************/
  1644. {
  1645. /*-------------------------- external data ----------------------------*/
  1646.  extern CHARTYPE *temp_cmd;
  1647. /*--------------------------- local data ------------------------------*/
  1648.  register short i=0;
  1649.  short num_retr = min(num,num_recv);
  1650. /*--------------------------- processing ------------------------------*/
  1651. #ifdef TRACE
  1652.  trace_function("util.c:    get_from_recovery_list");
  1653. #endif
  1654. /*---------------------------------------------------------------------*/
  1655. /* Return error if nothing to recover.                                 */
  1656. /*---------------------------------------------------------------------*/
  1657.  if (retr_recv == (-1))
  1658.    {
  1659.     display_error(0,(CHARTYPE *)"0 line(s) recovered",TRUE);
  1660. #ifdef TRACE
  1661.     trace_return();
  1662. #endif
  1663.     return;
  1664.    }
  1665. /*---------------------------------------------------------------------*/
  1666. /* Retrieve each allocated recovery line and put back into the body.   */
  1667. /*---------------------------------------------------------------------*/
  1668.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1669.  for (i=0;i<num_retr;i++)
  1670.    {
  1671.     if (recv[retr_recv] != NULL)
  1672.       {
  1673.        insert_new_line(recv[retr_recv],recv_len[retr_recv],1L,get_true_line(),TRUE,FALSE,CURRENT_VIEW->display_low);
  1674.        retr_recv = (--retr_recv < 0) ? num_recv-1 : retr_recv;
  1675.       }
  1676.    }
  1677.  sprintf(temp_cmd,"%d line(s) recovered",num_retr);
  1678.  display_error(0,(CHARTYPE *)temp_cmd,TRUE);
  1679. #ifdef TRACE
  1680.  trace_return();
  1681. #endif
  1682.  return;
  1683. }
  1684. /***********************************************************************/
  1685. #ifdef PROTO
  1686. void free_recovery_list(void)
  1687. #else
  1688. void free_recovery_list()
  1689. #endif
  1690. /***********************************************************************/
  1691. {
  1692. /*--------------------------- local data ------------------------------*/
  1693.  register short i=0;
  1694. /*--------------------------- processing ------------------------------*/
  1695. #ifdef TRACE
  1696.  trace_function("util.c:    free_recovery_list");
  1697. #endif
  1698.  for (i=0;i<MAX_RECV;i++)
  1699.    {
  1700.     if (recv[i] != NULL)
  1701.       {
  1702.        (*the_free)(recv[i]);
  1703.        recv[i] = NULL;
  1704.       }
  1705.    }
  1706.  add_recv  = (-1);
  1707.  retr_recv = (-1);
  1708.  num_recv  = 0;
  1709. #ifdef TRACE
  1710.  trace_return();
  1711. #endif
  1712.  return;
  1713. }
  1714.  
  1715. #if THIS_APPEARS_TO_NOT_BE_USED
  1716. /***********************************************************************/
  1717. #ifdef PROTO
  1718. WINDOW *adjust_window(WINDOW *win,short tr,short tc,short lines,short cols)
  1719. #else
  1720. WINDOW *adjust_window(win,tr,tc,lines,cols)
  1721. WINDOW *win;
  1722. short tr;
  1723. short tc;
  1724. short lines;
  1725. short cols;
  1726. #endif
  1727. /***********************************************************************/
  1728. {
  1729. /*--------------------------- local data ------------------------------*/
  1730.  WINDOW *neww=NULL;
  1731.  short begy=0,begx=0,maxy=0,maxx=0,y=0,x=0;
  1732.  short rc=RC_OK;
  1733. /*--------------------------- processing ------------------------------*/
  1734. #ifdef TRACE
  1735.  trace_function("util.c:    adjust_window");
  1736. #endif
  1737. /*---------------------------------------------------------------------*/
  1738. /* Get existing details about the current window.                      */
  1739. /*---------------------------------------------------------------------*/
  1740.  getbegyx(win,begy,begx);
  1741.  getmaxyx(win,maxy,maxx);
  1742.  if (maxy == lines && maxx == cols)  /* same size */
  1743.    {
  1744.     if (begy == tr && begx == tc)   /* same position */
  1745.       {
  1746. #ifdef TRACE
  1747.        trace_return();
  1748. #endif
  1749.        return(win); /* nothing to do, return same window */
  1750.       }
  1751.     else /* need to move window */
  1752.       {
  1753.        rc = mvwin(win,tr,tc);
  1754. #ifdef TRACE
  1755.        trace_return();
  1756. #endif
  1757.        return(win);
  1758.       }
  1759.    }
  1760. /*---------------------------------------------------------------------*/
  1761. /* To get here the window needs to be resized.                         */
  1762. /*---------------------------------------------------------------------*/
  1763.  getyx(win,y,x);
  1764.  delwin(win);
  1765.  neww = newwin(lines,cols,tr,tc);
  1766.  if (neww != (WINDOW *)NULL)
  1767.     wmove(neww,y,x);
  1768. #ifdef TRACE
  1769.  trace_return();
  1770. #endif
  1771.  return(neww);
  1772. }
  1773. #endif
  1774.  
  1775. /***********************************************************************/
  1776. #ifdef PROTO
  1777. void draw_cursor(bool visible)
  1778. #else
  1779. void draw_cursor(visible)
  1780. bool visible;
  1781. #endif
  1782. /***********************************************************************/
  1783. {
  1784. /*-------------------------- external data ----------------------------*/
  1785.  extern bool INSERTMODEx;
  1786. /*--------------------------- local data ------------------------------*/
  1787. /*--------------------------- processing ------------------------------*/
  1788. #ifdef TRACE
  1789.  trace_function("util.c:    draw_cursor");
  1790. #endif
  1791. #if !defined(NO_CURS_SET)
  1792.  if (visible)
  1793.    {
  1794.     if (INSERTMODEx)
  1795.        curs_set(2);   /* block cursor */
  1796.     else
  1797.        curs_set(1);   /* underline cursor */
  1798.    }
  1799.  else
  1800.     curs_set(0);      /* cursor off */
  1801. #endif
  1802.  
  1803. #ifdef TRACE
  1804.  trace_return();
  1805. #endif
  1806.  return;
  1807. }
  1808. /***********************************************************************/
  1809. #ifdef PROTO
  1810. short my_wclrtoeol(WINDOW *win)
  1811. #else
  1812. short my_wclrtoeol(win)
  1813. WINDOW *win;
  1814. #endif
  1815. /***********************************************************************/
  1816. {
  1817. /*--------------------------- local data ------------------------------*/
  1818.  register short i=0;
  1819.  short x=0,y=0,maxx=0,maxy=0;
  1820. /*--------------------------- processing ------------------------------*/
  1821. #ifdef TRACE
  1822.  trace_function("util.c:    my_wclrtoeol");
  1823. #endif
  1824.  if (win != (WINDOW *)NULL)
  1825.    {
  1826.     getyx(win,y,x);
  1827.     getmaxyx(win,maxy,maxx);
  1828.     for (i=x;i<maxx;i++)
  1829.        mvwaddch(win,y,i,' ');
  1830.     wmove(win,y,x);
  1831.    }
  1832. #ifdef TRACE
  1833.  trace_return();
  1834. #endif
  1835.  return(0);
  1836. }
  1837. /***********************************************************************/
  1838. #ifdef PROTO
  1839. short my_wdelch(WINDOW *win)
  1840. #else
  1841. short my_wdelch(win)
  1842. WINDOW *win;
  1843. #endif
  1844. /***********************************************************************/
  1845. {
  1846. /*--------------------------- local data ------------------------------*/
  1847.  register short i=0;
  1848.  short x=0,y=0,maxx=0,maxy=0;
  1849. /*--------------------------- processing ------------------------------*/
  1850. #ifdef TRACE
  1851.  trace_function("util.c:    my_wdelch");
  1852. #endif
  1853.  
  1854.  getyx(win,y,x);
  1855.  getmaxyx(win,maxy,maxx);
  1856.  wdelch(win);
  1857.  mvwaddch(win,y,maxx-1,' ');
  1858.  wmove(win,y,x);
  1859.  
  1860. #ifdef TRACE
  1861.  trace_return();
  1862. #endif
  1863.  return(0);
  1864. }
  1865. /***********************************************************************/
  1866. #ifdef PROTO
  1867. short get_word(CHARTYPE *string,LENGTHTYPE length,LENGTHTYPE curr_pos,
  1868.                LENGTHTYPE *first_col,LENGTHTYPE *last_col)
  1869. #else
  1870. short get_word(string,length,curr_pos,first_col,last_col)
  1871. CHARTYPE *string;
  1872. LENGTHTYPE length,curr_pos;
  1873. LENGTHTYPE *first_col,*last_col;
  1874. #endif
  1875. /***********************************************************************/
  1876. {
  1877. #define FIRST_BLANK  0
  1878. #define SECOND_BLANK 1
  1879. #define FIRST_WORD   2
  1880. #define SECOND_WORD  3
  1881. /*--------------------------- local data ------------------------------*/
  1882.  short state=0,cursor_off=0;
  1883.  short num_cols=0;
  1884.  register short i=0;
  1885. /*--------------------------- processing ------------------------------*/
  1886. #ifdef TRACE
  1887.  trace_function("util.c:    get_word");
  1888. #endif
  1889. /*---------------------------------------------------------------------*/
  1890. /* If we are after the last column of the line, then just ignore the   */
  1891. /* command and leave the cursor where it is.                           */
  1892. /*---------------------------------------------------------------------*/
  1893.  if (curr_pos >= length)
  1894.    {
  1895. #ifdef TRACE
  1896.     trace_return();
  1897. #endif
  1898.     return(0);
  1899.    }
  1900. /*---------------------------------------------------------------------*/
  1901. /* Determine the end   of the next word, or go to the end of the line  */
  1902. /* if already at or past beginning of last word.                       */
  1903. /*---------------------------------------------------------------------*/
  1904.  cursor_off = num_cols = 0;
  1905.  if (*(string+curr_pos) == ' ')
  1906.     state = FIRST_BLANK;
  1907.  else
  1908.    {
  1909.     state = FIRST_WORD;
  1910.     for (i=curr_pos;;i--)
  1911.       {
  1912.        if (*(string+i) == ' '
  1913.        ||  i == -1)
  1914.          {
  1915.           cursor_off++;
  1916.           break;
  1917.          }
  1918.        cursor_off--;
  1919.       }
  1920.    }
  1921.  for (i=curr_pos+cursor_off;i<length;i++)
  1922.    {
  1923.     switch(state)
  1924.        {
  1925.         case FIRST_BLANK:
  1926.              if (*(string+i) != ' ')
  1927.                 state = FIRST_WORD;
  1928.              break;
  1929.         case FIRST_WORD:
  1930.              if (*(string+i) == ' ')
  1931.                 state = SECOND_BLANK;
  1932.              break;
  1933.         case SECOND_BLANK:
  1934.              if (*(string+i) != ' ')
  1935.                 state = SECOND_WORD;
  1936.              break;
  1937.        }
  1938.     if (state == SECOND_WORD)
  1939.        break;
  1940.     num_cols++;
  1941.    }
  1942.  *first_col = curr_pos + cursor_off;
  1943.  *last_col = *first_col + num_cols - 1;
  1944. #ifdef TRACE
  1945.  trace_return();
  1946. #endif
  1947.  return(1);
  1948. }
  1949. /***********************************************************************/
  1950. #ifdef PROTO
  1951. short my_wmove(WINDOW *win,short scridx,short winidx,short y,short x)
  1952. #else
  1953. short my_wmove(win,scridx,winidx,y,x)
  1954. WINDOW *win;
  1955. short scridx,winidx,y,x;
  1956. #endif
  1957. /***********************************************************************/
  1958. {
  1959. /*-------------------------- external data ----------------------------*/
  1960.  extern bool curses_started;
  1961. /*--------------------------- local data ------------------------------*/
  1962.  short rc=RC_OK;
  1963. /*--------------------------- processing ------------------------------*/
  1964. #ifdef TRACE
  1965.  trace_function("util.c:    my_wmove");
  1966. #endif
  1967. /*---------------------------------------------------------------------*/
  1968. /* If the scridx or winidx are -1, do not try to save the x/y position.*/
  1969. /*---------------------------------------------------------------------*/
  1970.  if (scridx != (-1)
  1971.  &&  winidx != (-1))
  1972.    {
  1973.     screen[scridx].screen_view->x[winidx] = x;
  1974.     screen[scridx].screen_view->y[winidx] = y;
  1975.    }
  1976.  if (curses_started)
  1977.     wmove(win,y,x);
  1978. #ifdef TRACE
  1979.  trace_return();
  1980. #endif
  1981.  return(rc);
  1982. }
  1983. /***********************************************************************/
  1984. #ifdef PROTO
  1985. short get_row_for_tof_eof(short row,CHARTYPE scridx)
  1986. #else
  1987. short get_row_for_tof_eof(row,scridx)
  1988. short row;
  1989. CHARTYPE scridx;
  1990. #endif
  1991. /***********************************************************************/
  1992. {
  1993. /*-------------------------- external data ----------------------------*/
  1994. /*--------------------------- local data ------------------------------*/
  1995. /*--------------------------- processing ------------------------------*/
  1996. #ifdef TRACE
  1997.  trace_function("util.c:    get_row_for_tof_eof");
  1998. #endif
  1999.  if (screen[scridx].sl[row].line_type == LINE_OUT_OF_BOUNDS_ABOVE)
  2000.    {
  2001.     for(;screen[scridx].sl[row].line_type != LINE_TOF_EOF;row++)
  2002.        ;
  2003.    }
  2004.  if (screen[scridx].sl[row].line_type == LINE_OUT_OF_BOUNDS_BELOW)
  2005.    {
  2006.     for(;screen[scridx].sl[row].line_type != LINE_TOF_EOF;row--)
  2007.        ;
  2008.    }
  2009. #ifdef TRACE
  2010.  trace_return();
  2011. #endif
  2012.  return(row);
  2013. }
  2014.